<template>
    <div>
        <base-list ref="appVersion" :condition="condition" :datas.sync="appVersion" :pageSearch="pageSearch">
            <el-form :inline="true" :model="condition" class="search-form" slot="search" label-width="80px">
                <el-row>
                    <el-col :span="7" class="search-width4">
                        <el-form-item label="版本代码">
                            <auto-search-app-version @selectName="v=>condition['search_LIKE_versionName']=v" :name="condition['search_LIKE_versionName']"></auto-search-app-version>
                        </el-form-item>
                    </el-col>
                    <el-col :span="7" class="search-width4">
                        <el-form-item label="应用类型">
                            <auto-search-app-info @selectName="v=>condition['search_LIKE_appName']=v" :name="condition['search_LIKE_appName']"></auto-search-app-info>
                        </el-form-item>
                    </el-col>
                    <el-col :span="3">
                        <el-button type="primary" icon="el-icon-search" @click="loadData" class="ml-80">查 询</el-button>
                    </el-col>
                </el-row>
            </el-form>
            <el-row slot="status">
                <el-col :span="24">
                    <el-button type="primary" formVisible="true" icon="el-icon-plus" @click="handleDialogFormOpen(false)" v-if="power('WPTMGR_SYSMGR_APPVERSION:ADD')">新增
                        </el-button>
                </el-col>
            </el-row>
            <el-table slot="list" :data="appVersion" border stripe max-height="500">
                <el-table-column type="index" fixed="left" label="序号" width="55"></el-table-column>
                <el-table-column prop="versionCode" label="版本代码"  min-width="120"></el-table-column>
                <el-table-column prop="versionName" label="版本名称"  min-width="120"></el-table-column>
                <el-table-column prop="appName" label="应用名称"  min-width="120"></el-table-column>
                <el-table-column prop="updateUrl" label="更新地址"  min-width="120"></el-table-column>
                <el-table-column prop="force" label="强制更新"  min-width="120">
                    <template slot-scope='scope'>
                        {{ scope.row.force | _filterTrueOrFalse }}
                    </template>
                </el-table-column>
                <el-table-column fixed="right" align="center" label="操作"  width="140">
                    <template slot-scope="scope">
                        <el-button size="small" type="text" @click="handleDialogFormOpen(true,scope.row)" v-if="power('WPTMGR_SYSMGR_APPVERSION:UPD')">编辑</el-button>
                        <el-button type="text" class="danger" size="small" @click="handleRemove(scope.row)" v-if="power('WPTMGR_SYSMGR_APPVERSION:DEL')">删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </base-list>
        <app-version-form ref="appVersionForm" @load="loadData"></app-version-form>
    </div>
</template>

<script>
import { getAppVersion, deleteAppVersion } from "@/api/system/appVersion";
import appVersionForm from "./appVersionForm";
import autoSearchAppInfo from "@/components/autocomplete/autoSearchAppInfo";
import autoSearchAppVersion from "@/components/autocomplete/autoSearchAppVersion";
import autoSearchDic from "@/components/autocomplete/autoSearchDic";

export default {
    name: "应用版本管理",
    components: { appVersionForm, autoSearchAppInfo, autoSearchDic,autoSearchAppVersion },
    data() {
        return {
            condition: {}, // 查询条件
            appVersion: [], // table数组
            pageSearch: getAppVersion // 分页查询api接口
        };
    },
    mounted() {
        this.loadData();
    },
    methods: {
        loadData() {
            this.$refs.appVersion.loadData();
        },
        handleDialogFormOpen(bool, item) {
            if (bool) {
                let form = JSON.parse(JSON.stringify(item));
                this.$refs.appVersionForm.form = {
                    id: form.id,
                    versionCode: form.versionCode,
                    versionName: form.versionName,
                    appName: form.appName,
                    appId: form.appId,
                    force: form.force,
                    attachments: form.attachments,
                    versionDesc: form.versionDesc,
                    updateUrl: form.updateUrl,
                };
                this.$refs.appVersionForm.isEdit = true;
                this.$refs.appVersionForm.dialogForm = true;
            } else {
                this.$refs.appVersionForm.dialogForm = true;
            }
        },
        handleRemove(item) {
            this.$confirm(`是否删除该数据?`, "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            })
                .then(() => {
                    deleteAppVersion(item.id).then(res => {
                        this.$message({
                            type: "success",
                            message: `删除成功!`
                        });
                        this.loadData();
                    });
                })
                .catch(() => {
                    this.$message({
                        type: "info",
                        message: "已取消"
                    });
                });
        }
    }
};
</script>

<style scoped>
</style>
